package com.webcash.CNBoard.Validation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

import com.webcash.CNBoard.Model.Login;
import com.webcash.CNBoard.Service.EmployeeService;


@Component
public class LoginValidator implements Validator {
	
	@Autowired
	EmployeeService employeeService;
	
	public boolean supports(Class clazz) {
		return Login.class.isAssignableFrom(clazz);
	}

	public void validate(Object obj, Errors errors) {
		Login login = (Login)obj;
		
		int result = employeeService.checkValidation(login.getId(), login.getPassword());
		
		if(result == 0){
			errors.rejectValue("id", "not.exist.id");
		}
		if(result == 1){
			errors.rejectValue("password", "not.match.password");
		}
		
		
	}

}
